#include "common.h"
#include "encode.h"
#include "decode.h"
#include <cmath>
#include <iostream>
int main()
{
    for (float exp=0.5;exp<9;exp+=0.001)
    {
        float qs=exp;
        int nbits;
        encode(qs,nbits);
        decode(qs);
        int d1,d2;
        float * img1=readImg(d1,d2,ORIGINAL_IMG);
        float * img2=readImg(d1,d2,RECONSTRUCTED_IMG);
        float sum=0;
        for (int i=0;i!=d1;++i)
        {
            for (int j=0;j!=d2;++j)
            {
                sum+=pow(img1[i*d1+j]-img2[i*d1+j],2);
            }
        }
        float mse=sum/d1/d2;
        float psnr=10*log(255*255/mse)/log(10);
        float bpp=(float)nbits/d1/d2;
        std::cout<<qs<<"\t"<<psnr<<"\t"<<bpp<<std::endl;
    }


    return 0;
}
